package com.goldze.mvvmhabit.ui.leave_recording;

import android.databinding.ObservableField;
import android.support.annotation.NonNull;

import com.goldze.mvvmhabit.entity.response.GetLeaveListResponseEntity;
import com.goldze.mvvmhabit.utils.UserManager;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;


public class LeaveRecordingItemViewModel extends ItemViewModel<LeaveRecordingListViewModel> {

    public ObservableField<GetLeaveListResponseEntity.DataBean> entity = new ObservableField<>();

    public LeaveRecordingItemViewModel(@NonNull LeaveRecordingListViewModel viewModel, GetLeaveListResponseEntity.DataBean entity) {
        super(viewModel);
        this.entity.set(entity);
    }

    /**
     * 获取position的方式有很多种,indexOf是其中一种，常见的还有在Adapter中、ItemBinding.of回调里
     *
     * @return
     */
    public int getPosition() {
        return viewModel.getItemPosition(this);
    }

    public String getNumSign() {
        return String.valueOf(getPosition() + 1);
    }

    public String getName() {
        if (UserManager.getAppManager().getmUserInfo() != null) {
            return UserManager.getAppManager().getmUserInfo().getNickName();
        }
        return "";
    }

    public String getReason() {
        return "请假事由: " + entity.get().getReason();
    }

    /**
     * 回退理由
     *
     * @return
     */
    public String getReturnBackReason() {
        return (String) entity.get().getRefuseReason();
    }

    public String tabText() {
        return returnTabText(entity.get().getState());
    }

    private String returnTabText(int state) {
        String tabText = "";
        switch (state) {
            case 0:
                tabText = "待审批";
                break;
            case 1:
                tabText = "通 过";
                break;
            case 2:
                tabText = "不同意";
                break;
            default:
                tabText = "";
        }

        return tabText;
    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

        }
    });
}
